package com.magiccompass.alipay.barcode.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.magiccompass.alipay.barcode.entity.MerchantGroup;
import com.magiccompass.alipay.barcode.entity.MerchantInfo;

public class CollectionUtil {
	public static LinkedHashMap<Integer, String> transferMerchantList(List<MerchantInfo> merchantList){
		LinkedHashMap<Integer, String> returnMap = new LinkedHashMap<Integer, String>();
		for(MerchantInfo aMerchant:merchantList){
			returnMap.put(aMerchant.getId(), aMerchant.getMerchantName());
		}
		return returnMap;
	}
	
	public static String parameterMap2SignString(Map<String, String> sortedParams) {
        StringBuffer content = new StringBuffer();
        List<String> keys = new ArrayList<String>(sortedParams.keySet());
        Collections.sort(keys);
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = sortedParams.get(key);
            if (StringUtil.areNotEmpty(key, value)) {
                content.append((i == 0 ? "" : "&") + key + "=" + value);
            }
        }
        return content.toString();
    }
	public static LinkedHashMap<Integer, String> transferMerchantGroupList(List<MerchantGroup> merchantGroupList){
		LinkedHashMap<Integer, String> returnMap = new LinkedHashMap<Integer, String>();
		for(MerchantGroup aMerchantGroup:merchantGroupList){
			returnMap.put(aMerchantGroup.getId(), aMerchantGroup.getGroupName());
		}
		return returnMap;
	}
}
